package com.cjg.lock;

import java.util.concurrent.atomic.AtomicReference;

public class skiplock {
    //创建一个原子性线程
    AtomicReference<Thread> aT = new AtomicReference<>();
    public void lock(){
        Thread thread = Thread.currentThread();
        System.out.println(Thread.currentThread().getName()+"==lock");
       while (!aT.compareAndSet(null,thread)){

       }
    }

    public void unlock(){
        Thread thread = Thread.currentThread();
        System.out.println(Thread.currentThread().getName()+"==unlock");
        aT.compareAndSet(thread,null);
    }

}
